// Tags:
#include <algorithm>
#include <cctype>
#include <cstdio>

typedef long long ll;

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

const int N = 1e5 + 5, inf = 0x3f3f3f3f;
int n, q, lim, a[N], son[N];
int e_cnt, heads[N];
bool vis[N], avi[N];
ll f[N], g[N];

struct Edge {
  int v, nxt;
} e[N << 1];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

void pre(int u, int fa) {
  vis[u] = true;
  for (int i = heads[u], v; i; i = e[i].nxt) {
    if (avi[v = e[i].v] && v != fa) {
      pre(v, u);
      if (f[v] + a[u] >= f[u]) g[u] = f[u], f[u] = f[v] + a[u], son[u] = v;
      else if (f[v] + a[u] > g[u])
        g[u] = f[v] + a[u];
    }
  }
}

void solve(int u, int fa) {
  ll tmp = (son[fa] == u ? g[fa] : f[fa]) + a[u];
  if (tmp >= f[u]) {
    g[u] = f[u], f[u] = tmp, son[u] = fa;
  } else if (tmp > g[u])
    g[u] = tmp;
  for (int i = heads[u], v; i; i = e[i].nxt) {
    if (avi[v = e[i].v] && v != fa) { solve(v, u); }
  }
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen64("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen64("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("diamond.in", "r", stdin);
  freopen("diamond.out", "w", stdout);
#endif
#endif

  read(n), read(q);
  for (int i = 1; i <= n; ++i) { read(a[i]); }
  for (int i = 1, u, v; i < n; ++i) {
    read(u), read(v);
    add(u, v), add(v, u);
  }
  for (int i = 1; i <= q; ++i) {
    read(lim);
    std::fill(vis, vis + n + 1, false);
    std::fill(avi, avi + n + 1, false);
    for (int i = 1; i <= n; ++i) {
      f[i] = 0, g[i] = -inf;
      if (a[i] <= lim) avi[i] = true, f[i] = a[i], g[i] = a[i];
    }
    for (int i = 1; i <= n; ++i) {
      if (!vis[i] && avi[i]) pre(i, 0), solve(i, 0);
    }
    for (int i = 1; i <= n; ++i) {
      printf("%lld", std::max(0ll, std::max(f[i], f[i] + g[i] - a[i]))),
          putchar(" \n"[i == n]);
    }
  }
  return 0;
}